package com.myccb.app.view.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.myccb.app.R;
import com.myccb.app.base.BaseActivity;
import com.myccb.app.widget.CommonToolBar;
import com.myccb.app.widget.rollpageview.ColorPointHintView;
import com.myccb.app.widget.rollpageview.LoopPagerAdapter;
import com.myccb.app.widget.rollpageview.RollPagerView;

public class MenuItemActivity extends BaseActivity {

    public static void launchMenuLayout(int id, Context context){
        Intent intent=new Intent(context,MenuItemActivity.class);
        int layoutId= R.layout.menu_massage;
        switch (id){
            case R.id.nav_info:
                layoutId=R.layout.menu_massage;
                break;
            case R.id.nav_about:
                layoutId=R.layout.menu_about;
                break;
            case R.id.nav_find:
                layoutId=R.layout.activity_menu_discover;
                break;
            case R.id.nav_recommend:
                layoutId=R.layout.menu_recommend;
                break;
            case R.id.nav_security_center:
                layoutId=R.layout.menu_security;
                break;
            case R.id.nav_setting:
                layoutId=R.layout.menu_settings;
                break;
        }
        intent.putExtra("layoutId",layoutId);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        int layoutId= getIntent().getIntExtra("layoutId",R.layout.menu_massage);
        setContentView(layoutId);
        if (layoutId == R.layout.activity_menu_discover) {
            RollPagerView indexAdv = findViewById(R.id.menu_myviewpager);

            indexAdv.setHintView(new ColorPointHintView(this,getResources().getColor(R.color.colorPrimary),getResources().getColor(R.color.Grey200)));
            indexAdv.setAdapter(new LoopPagerAdapter(indexAdv) {
                private int[] adImgs={
                        R.mipmap.index_main_home_adv_1, R.mipmap.index_main_home_adv_2,
                        R.mipmap.index_main_home_adv_3, R.mipmap.index_main_home_adv_4
                };
                @Override
                public View getView(ViewGroup container, int position) {
                    ImageView view = new ImageView(container.getContext());
                    view.setImageResource(adImgs[position]);
                    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                    return view;
                }
                @Override
                public int getRealCount() {
                    return adImgs.length;
                }
            });
        }
        initView();
    }
    private void initView(){
        CommonToolBar commonToolBar=findViewById(R.id.common_toolbar);

        setSupportActionBar(commonToolBar.getToolbar());

        commonToolBar.setOnLeftButtonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
